<?php

namespace App\Http\Controllers;

use App\B2BProject\Custom\Business\Brand;
use App\B2BProject\Custom\Business\GoodsCategory;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class GoodsBrandCategoryGetterController extends Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->middleware('auth', ['only' => 'getGrantBrands']);
    }

    public function getIndex()
    {
        $parents = Brand::all();
        $data    = [];
        $item    = ['categTitle' => '品牌列表'];
        foreach ($parents as $parent) {
            $item['categDetail'][] = ['txt' => $parent->name, 'code' => $parent->id];
        }
        $data['data'][] = $item;

        return response()->json($data);
    }

    public function getGrantBrands()
    {
        $brands = \Auth::user()->store->mainBrand;

        $data = [];
        $item    = ['categTitle' => '品牌列表'];
        foreach ($brands as $brand) {
            $item['categDetail'][] = ['txt' => $brand->name, 'code' => $brand->id, 'imgsrc' => $brand->logo];
        }
        $data['data'][] = $item;

        return response()->json($data);
    }
}
